package com.bawei.module_apps

import android.content.Context
import android.util.Log
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import java.lang.RuntimeException


@Interceptor(priority = 8,name = "登陆拦截")
class MyRouterInterceptor:IInterceptor {
    override fun init(context: Context?) {

    }
    //登陆拦截
    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        val path = postcard?.path

        if("/apps/local".equals(path) || "/attendance/signactivity".equals(path)){//打开本地/签到应用前必须登陆
            val flag = SPUtils.getInstance().getBoolean("login")
            if(!flag){
                ARouter.getInstance().build("/launcher/login").navigation()
                callback!!.onInterrupt(Throwable("该用户没有登陆"))//拦截住
                return
            }
        }
        callback!!.onContinue(postcard)//继续执行

    }
}